/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MUDPLAYER_H
#define MUDPLAYER_H

#include "MudMobile.h"
#include "ItemContainer.h"
#include "Equipment.h"
#include "Activity.h"

namespace Chronos {

class Session;
class MudItem;
class MudWearable;
class Database;
class Trade;

class MudPlayer : public MudMobile {
public:
    MudPlayer(Session& session_, int id_, const Stats& stats_);
    virtual void accept(CmdVisitor& v);
   
    const std::string& getOption(const std::string& setting) const;

    virtual void write(const std::string& text);

    virtual void generateEvent(MudObjectEvent event);
    
    virtual unsigned int doCombat();
    virtual void miss(MudMobile& source);
    virtual bool takeDmg(MudMobile& source, unsigned int dmg);

    void addItem(MudItem* item);
    MudItem* findItem(const std::string& name) const;

    MudItem* findInInventory(const std::string& name) const;
    void removeItem(const MudItem* name);
    void visitInventory(ConstItemVisitor& visitor) const;
    void visitInventory(ItemVisitor& visitor);

    MudWearable* findInEquipment(const std::string& name) const;
    void wear(MudWearable* equip);
    void unwear(MudWearable* equip);
    const Equipment& getEquipment() const;

    unsigned int getCredits() const;
    void setCredits(unsigned int amount);
    void addCredits(int amount);

    int getID() const;

    void setActivity(Activity* activity);
    bool cancelActivity();

    bool inTrade() const;
    void setTrade(Trade* trade_);
    Trade* getTrade() const;

    void save(Database& database) const;
    static MudPlayer& load(Database& database, const std::string& name, Session& session);
    static void create(Database& database, const std::string& name, const std::string& password);
private:
    void deserializeInv(const char* input);
    void deserializeEquipment(const char* input);

    Session& session;
    int databaseID;
	unsigned int credits;
    Equipment equipment;
    ItemContainer inventory;
    ActivityManager activityManager;
    Trade* trade;
};

}

#endif

